package com.mriassl.consumer.user.web;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.mriassl.consumer.user.domain.User;
import com.mriassl.consumer.user.service.UserService;


@RestController
public class UserController {

	@Autowired
	UserService userService;
	
	@RequestMapping(value="/hello", method=RequestMethod.GET)
	public String hello(){
		return userService.helloServie();
	}
	
	@RequestMapping(value="/user", method=RequestMethod.GET)
	public User user(String id){
		return userService.findById(id);
//		HystrixRequestContext existingState = HystrixRequestContext.initializeContext();
//        try {
//        	return new UserCollapseCommand(userService, id).execute();
//        } finally {
//            HystrixRequestContext.setContextOnCurrentThread(existingState);
//        }
	}

	@RequestMapping(value="/users", method=RequestMethod.GET)
	public List<User> user(String[] ids){
		return userService.findByIds(Arrays.asList(ids));
//		return new UserBatchCommand(userService, ids).execute();
	}
}
